package com.riguz.forks.framework.mvc;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class RequestContext implements AutoCloseable {

    private static final ThreadLocal<HttpServletRequest>  request  = new ThreadLocal<>();
    private static final ThreadLocal<HttpServletResponse> response = new ThreadLocal<>();

    public RequestContext(HttpServletRequest request, HttpServletResponse response) {
        RequestContext.request.set(request);
        RequestContext.response.set(response);
    }

    public static HttpServletRequest getRequest() {
        return request.get();
    }

    public static HttpServletResponse getResponse() {
        return response.get();
    }

    @Override
    public void close(){
        request.remove();
        response.remove();
        
    }

}
